package com.cn.jinl.controller;

import com.cn.jinl.api.IProductStorageService;
import com.cn.jinl.domain.ProductStorage;
import com.cn.jinl.domain.ProductStorageMXVo;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/productStorage")
public class ProductStorageController {

    @Autowired
    private IProductStorageService productStorageService;

    @RequestMapping("/getProductStorageList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductStorage>> getProductStorageList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<ProductStorage>> response = new JsonResponse<>();
        List<ProductStorage> productStorages = productStorageService.getProductStorageList(queryForm);
        response.setResult(productStorages);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getProductStorageById/{frontToken}")
    @ResponseBody
    public JsonResponse<ProductStorage> getProductStorageById(String id, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<ProductStorage> response = new JsonResponse<>();
        ProductStorage productStorage = productStorageService.getProductStorageById(id);
        response.setResult(productStorage);
        response.setSuccess(true);
        return response;
    }

    //入库生产明细
    @RequestMapping("/getProductStorageMXList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductStorageMXVo>> getProductStorageMXList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<ProductStorageMXVo>> response = new JsonResponse<>();
        List<ProductStorageMXVo> productStorages = productStorageService.getProductStorageMXList(queryForm);
        response.setResult(productStorages);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/api/updateTestBatchProductStorage")
    @ResponseBody
    public JsonResponse<String> updateTestBatchProductStorage() throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productStorageService.updateTestBatchProductStorage();
        return CommonUtil.getResponseData(response,result);
    }
}
